*************************************************************************************
* This README provides instructions on how to run code that replicates key facts	*
* and figures from "Indebted Demand" by Atif Mian, Ludwig Straub, and Amir Sufi		*  
* Date: January 12, 2021															*
*************************************************************************************

Overview: All results can be replicated by running main_unified.m, which is divided into sections %% (1a) - (3). The first set of sections sets up the environment. The second and third set of sections replicate results for the model without capital, and with capital, respectively.

1. How to replicate plots and results:

First, set compile_pdf = 0 and write_tikz  = 0 and specify file paths in in Code Section (1a) to generate and save plots. Most importantly, specify where your latex compiler is located and save it to H.pdflatexpath. The tikz and compile_pdf paths specify where tikz files and pdfs of the figures will be saved. 

Run Code Sections (1a)-(1g) to set up the common environment and auxiliary structs and functions. 

i. For Figures:
Paper Section 5.1 Figures 7+8: Run Code Section (2a)
Paper Section 6.1 Figure 11: Run Code Section (2b)
Paper Section 7.1 Figure 13: Run Code Section (2c)
Paper Section 9 Figure 15: Run Code Section (3)

ii. For calibration:
Paper Section 3.5 Lambda calibration (Romer+Romer shock): Run Code Section (1h)


2. List of files and folders

i: main file

main_unified.m: main file, divided into several sections
 * Run section (1) to set up the environment:
	- (1a) Plot options: set compile_pdf and write_tikz = 1 to produce tikz plots
	- (1b) Parameters: declares parameters and baseline shock paths
	- (1c) Common Structs: sets common structs (parameters, shocks, plot options) to be used later
	- (1d) Calibration: calibrates eta_tilde, a_tilde and k_ss to match target values of steady state interest rate, debt and MPC out of capital gains
	- (1e) Steady state with greater inequality: computes high inequality steady state in model with capital
	- (1f) Simple model's steady state: computes steady state in model without capital
	- (1g) Steady state with greater inequality in simple model: computes high inequality steady state in model without capital
	- (1h) MP SHOCK with nat rate afterwards (RR shock for calibration): computes debt/GDP response to a Romer + Romer (2004) shock
 * Run Section (2) to replicate plots for the simple model (without capital)
	- (2a) Replicate the simple model's inequality transition here: Figures 7 + 8, computes the transitional dynamics between low and high-inequality steady state
	- (2b) Deficit spending (no ZLB): Figure 11, computes transitional dynamics to a deficit-financed government spending shock
	- (2c) Falling into the liquidity trap in response to greater inequality: Figure 13, computes transitional dynamics from low to high inequality in the presence of a lower bound
 * Run Section (3) to replicate plots for the quantative model (with capital)
	- (3) Rising income inequality Q: Figure 15, computes the transitional dynamics between low and high-inequality steady state in the model with capital for various parameter choices (homothetic model, different Allen elasticities, non-perfect foresight transition)

ii: helper functions (computation)

calibrate_unified.m: calibrates eta1, a_thresh and k_ss to match targets 
compute_pe_unified.m: computes partial equilibrium dynamics for state-level exercise (section 4.3)
compute_td_unified.m: computes transitional dynamics given shock/parameter paths
read_opt.m: wrapper function to transform a struct into a field
steadystate_unified.m: computes the steady state at time 0
steadystate_t_unified.m: computes the path of hypothetical 'steady states' given parameter transitions

iii: helper functions (tikz)
plot_this.m: plot function that calls write_tikz_file.m with plot options
create_ticks.m: creates tikz file
find_and_replace.m: regex aux
tikz2pdf.py: function to generate pdfs from .tikz if triggered via write_pdf = 1 in main file
write_tikz_file.m: writes tikz files

iv: folders (tikz)
tikz: output folder for tikz files
tikz_pdfs: output folder for tikz pdf plots
